
package com.xin.di.uav.applet.controller;

import com.xin.di.uav.applet.request.MerchantAddParam;
import com.xin.di.uav.applet.request.MerchantEditParam;
import com.xin.di.uav.applet.request.ServiceAreaEditParam;
import com.xin.di.uav.applet.resp.MerchantResp;
import com.xin.di.uav.applet.service.MerchantService;
import com.xin.di.uav.common.request.common.IdRequest;
import com.xin.di.uav.common.response.IdAndNameResp;
import com.xin.di.uav.common.utils.Rs;
import jakarta.validation.constraints.NotBlank;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;


@RestController
@RequestMapping("/home/merchant/")
public class MerchantController {
    @Autowired
    private MerchantService merchantService;

    @PostMapping("add")
    public Rs<Boolean> add(@RequestBody @Valid MerchantAddParam merchantAddParam) {
        return Rs.success(merchantService.add(merchantAddParam));
    }

    @PutMapping("update")
    public Rs<Boolean> update(@RequestBody @Valid MerchantEditParam merchantEditParam) {
        return Rs.success(merchantService.update(merchantEditParam));
    }

    @PutMapping("update-status")
    public Rs<Boolean> updateStatus(@RequestBody @Valid IdRequest idRequest) {
        return Rs.success(merchantService.updateStatus(idRequest));
    }


    @GetMapping("list")
    public Rs<MerchantResp> list(@RequestParam int page, @RequestParam int pageSize
            , @RequestParam(required = false) String merchantName) {
        return Rs.success(merchantService.list(page, pageSize, merchantName));
    }

    @GetMapping("get-id-and-name")
    public Rs<List<IdAndNameResp>> getIdAndName(@RequestParam() @NotBlank(message = "搜索名称不能为空") String serviceRegion) {
        return Rs.success(merchantService.getIdAndName(serviceRegion));
    }
}
